package com.huawei.userservice.controller;


import com.huawei.common.pojo.Result;
import com.huawei.common.pojo.pay;
import com.huawei.common.pojo.updateMoney;
import com.huawei.common.utils.ThreadLocalUtil;
import com.huawei.userservice.client.VideoClient;
import com.huawei.userservice.pojo.dto.UserDTO;
import com.huawei.userservice.pojo.entity.User;
import com.huawei.userservice.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.Pattern;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;




@Tag(name = "用户模块")
@RestController
@RequestMapping("/users")
@Validated
public class UserController {

    @Autowired
    private UserService userService;

    @Autowired
    private VideoClient videoClient;







//    @Value("${snowflakes.workerid}")
//    private Long workerId;
//    @Value("${snowflakes.datacenterid}")
//    private Long dataCenterId;

    @Operation(summary = "测试-获取用户信息")
    @GetMapping("/{id}")
    //测试用的接口
    public Result getUserId(@RequestHeader(name = "Authorization") String token , @PathVariable("id") Integer id, HttpServletResponse response){
        String video = videoClient.getByIdInner(1);
        System.out.println(video);
        String  s = "sd";
        String[] userInfo = ThreadLocalUtil.get();
        return Result.success("成功测试！" + userInfo[0] + " " + userInfo[1]);
    }


    @Operation(summary = "用户注册")
    @PostMapping("/register")
    //注册
    public Result register(@Pattern(regexp = "^\\S{4,16}$") String username,@Pattern(regexp = "^\\S{4,16}$") String password){
        return userService.register(username,password);
    }


    @Operation(summary = "用户登陆")
    @PostMapping("/login")
    //登陆
    public Result login(@Pattern(regexp = "^\\S{4,16}$") String username,@Pattern(regexp = "^\\S{4,16}$") String password){
        return userService.login(username,password);
    }


    @Operation(summary = "用户登出")
    @PostMapping("/logout")
    //登出
    public Result logout(@RequestHeader(name = "Authorization") String token){
        return userService.logout(token);
    }



    @Operation(summary = "延长token令牌时间一天")
    @PostMapping("/renew")
    public Result renew(@RequestHeader(name = "Authorization") String token){
        return userService.renew(token);
    }





    @Operation(summary = "更新用户信息")
    @PostMapping("/update")
    public Result update(@RequestHeader("Authorization") String token,@RequestBody UserDTO userDTO){
        return userService.updateUserInfo(userDTO);
    }



    @Operation(summary = "删除用户信息")
    @PostMapping("/delete")
    public Result delete(@RequestHeader("Authorization") String token){
        return userService.deleteUser(token);
    }


    @Operation(summary = "获取用户信息")
    @GetMapping("/getUserInfo")
    public Result getUserInfo(@RequestHeader("Authorization") String token){
        return userService.getUserInfo();
    }




    @Operation(summary = "更新用户抖乐号")
    @PostMapping("/updateId")
    public Result updateId(@RequestHeader("Authorization") String token,@RequestParam String douyueId){
        return userService.updateDyId(douyueId);
    }


    @Operation(summary = "更新账户金额")
    @PostMapping("/updateMoney")
    public Result updateMoney(@RequestBody updateMoney upMoney){
        System.out.println("******" +upMoney);
        return userService.updateMoney(upMoney.getId(),upMoney.getMoney());
    }



    @Operation(summary = "内部支付接口无法调用")
    @PostMapping("/pay")
    public Result pay(@RequestBody pay pay){
        return userService.pay(pay.getSetterId(),pay.getMoney());
    }













}
